import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-rabbitmq-producer.xml")
public class test {
    @Autowired
     private RabbitTemplate rabbitTemplate;

    @Test
    public void test1(){
        /**
         * 发送简单模式的消息
         * convertAndSend(String routingKey, Object message)
         */
        String body="Spring整合RabbitMq简单模式发送消息";
        rabbitTemplate.convertAndSend("spring_queue",body);
    }

    @Test
    public void test2(){
        /**
         * 发送路由模式的消息
         * convertAndSend(String exchange, String routingKey, Object object)
         */
        String body="Spring整合RabbitMq路由模式发送消息";
        rabbitTemplate.convertAndSend("spring_direct_exchange","direct1",body);
    }

    @Test
    public void test3(){
        /**
         * 发送路由广播模式的消息
         * convertAndSend(String exchange, String routingKey, Object object)
         */
        String body="Spring整合RabbitMq广播模式发送消息";
        rabbitTemplate.convertAndSend("spring_fanout_exchange","",body);
    }

    @Test
    public void test4(){
        /**
         * 发送路由通配符模式的消息
         * convertAndSend(String exchange, String routingKey, Object object)
         */
        String body="Spring整合RabbitMq通配符模式发送消息";
        rabbitTemplate.convertAndSend("spring_topic_exchange","heima.hehe",body);
    }
}
